package com.distributer.product.thread;

import java.util.concurrent.ArrayBlockingQueue;

import com.distributer.product.request.Request;

/**
 * 请求处理线程
 * @author Administrator
 *
 */
public class RequestHanderTask implements Runnable {

	private ArrayBlockingQueue<Request> requestQueues;

	public RequestHanderTask(ArrayBlockingQueue<Request> requestQueues) {
		this.requestQueues = requestQueues;
	}

	@Override
	public void run() {
		while (!Thread.currentThread().isInterrupted()) {
			if (requestQueues.isEmpty()) {
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				Request request = null;
				try {
					request = requestQueues.take();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				if (request != null) {
					request.process();
				}
			}
		}
	}
}
